package xyz.xuminghai.javafx_learn.scene.control;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.util.List;

/**
 * 2023/5/25 15:30 星期四<br/>
 * 树形控件
 *
 * @author xuMingHai
 */
public class TreeViewApp extends Application {

    private final HBox hBox = new HBox();

    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void init() {

        TreeItem<String> rootTreeItem = new TreeItem<>("root");

        rootTreeItem.getChildren().addAll(List.of(
                new TreeItem<>("child1"),
                new TreeItem<>("child2"),
                new TreeItem<>("child3")
        ));

        hBox.setAlignment(Pos.CENTER);
        hBox.setFillHeight(false);
        hBox.getChildren().add(new TreeView<>(rootTreeItem));
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(hBox, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
